package com.hbu.product.hbumallproduct.controller;

import com.hbu.common.utils.PageUtils;
import com.hbu.common.utils.R;
import com.hbu.product.hbumallproduct.entity.SpuInfoEntity;
import com.hbu.product.hbumallproduct.service.SpuInfoService;
import com.hbu.product.hbumallproduct.vo.SpuInfoListVO;
import com.hbu.product.hbumallproduct.vo.spusave.SpuSaveVO;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;


/**
 * spu??Ϣ
 *
 * @author zhaoxiaohan
 * @email 13315217827@163.com
 * @date 2022-10-27 22:52:07
 */
@RestController
@RequestMapping("hbumallproduct/spuinfo")
@AllArgsConstructor
public class SpuInfoController {

    private SpuInfoService spuInfoService;


    /**
     * spu检索
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public R list(SpuInfoListVO spuInfoList) {
        PageUtils page = spuInfoService.getList(spuInfoList);
        return R.ok().put("page", page);
    }

    /**
     * 商品上架
     */
    @RequestMapping(value = "/{spuId}/up",method = RequestMethod.POST)
    public R spuShelves(@PathVariable Long spuId){
        spuInfoService.spuShelves(spuId);
        return R.ok();
    }




    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        SpuInfoEntity spuInfo = spuInfoService.getById(id);

        return R.ok().put("spuInfo", spuInfo);
    }

    /**
     * 新增商品
     */
    @RequestMapping("/save")
    public R save(@RequestBody SpuSaveVO spuSaveVO) {
        spuInfoService.saveSpuSaveVO(spuSaveVO);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SpuInfoEntity spuInfo) {
        spuInfoService.updateById(spuInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids) {
        spuInfoService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
